#include "Moon.h"
#include "Planet.h"
#include <math.h> 

#define PI 3.14

Moon::Moon() {
	name = "";
	transX = 0;
	transY = 0;
	transZ = 0;
	size = 0;
	colorR = 0;
	colorG = 0;
	colorB = 0;
	rotX = 0;
	rotY = 0;
	rotZ = 0;
	cur_deg = 0;
	deg_inc = 0;
	esize = 0;
	edist = 0;
	radius = 0;
	orb_ecc = 0.0;
	xradius = 0;
	yradius = 0;
	zradius = 0;
}

Moon::Moon(std::string NameOfMoon) {
	esize = 1.0;
	edist = 25.0;

	if(NameOfMoon == "EarthMoon") {
		name == "EarthMoon";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.273;
		colorR = 0.0;
		colorG = 0.0;
		colorB = 1.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.0748);
		radius = (edist*.273+1)*.5;
		orb_ecc = 0.0549;
		xradius = 2.0 * radius;
		yradius = 5.145;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}

	if(NameOfMoon == "Deimos") {
		name == "Deimos";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.00812;  // .00001
		colorR = 1.0;
		colorG = 0.0;
		colorB = 0.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.003456);
		radius = edist*.00812+1;
		orb_ecc = 0.0002;
		xradius = 2.0 * radius;
		yradius = 27.58;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Phobos") {
		name == "Phobos";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.00812; //.00001
		colorR = 1.0;
		colorG = 0.0;
		colorB = 0.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.0008731);
		radius = edist*.00812+1;
		orb_ecc = 0.0151;
		xradius = 2.0 * radius;
		yradius = 26.04;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Callisto") {
		name == "Callisto";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.378; //.0541
		colorR = 1.0;
		colorG = 0.5;
		colorB = 0.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.04569);
		radius = edist*.378+1;
		orb_ecc = 0.0074;
		xradius = 2.0 * radius;
		yradius = 0.192;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Europa") {
		name == "Europa";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.245; //.0147
		colorR = 1.0;
		colorG = 0.5;
		colorB = 0.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.009722);
		radius = edist*.245+1;
		orb_ecc = 0.009;
		xradius = 2.0 * radius;
		yradius = 0.470;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Ganymede") {
		name == "Ganymede";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.413; //.0704
		colorR = 1.0;
		colorG = 0.5;
		colorB = 0.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.019588);
		radius = edist*.413+1;
		orb_ecc = 0.0013;
		xradius = 2.0 * radius;
		yradius = 0.20;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Io") {
		name == "Io";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.286; //.0234
		colorR = 1.0;
		colorG = 0.5;
		colorB = 0.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.004844);
		radius = edist*.286+1;
		orb_ecc = 0.0041;
		xradius = 2.0 * radius;
		yradius = 2.21;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Dione") {
		name == "Dione";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.088; //.0007
		colorR = 0.2;
		colorG = 0.7;
		colorB = 0.5;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.007493);
		radius = edist*.088+1;
		orb_ecc = 0.0022;
		xradius = 2.0 * radius;
		yradius = 0.019;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Enceladus") {
		name == "Enceladus";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.039; //.00006
		colorR = 0.2;
		colorG = 0.7;
		colorB = 0.5;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.003751);
		radius = edist*.039+1;
		orb_ecc = 0.0047;
		xradius = 2.0 * radius;
		yradius = 0.019;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Iapetus") {
		name == "Iapetus";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.113; //.0014
		colorR = 0.2;
		colorG = 0.7;
		colorB = 0.5;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.2172);
		radius = edist*.113+1;
		orb_ecc = 0.0286;
		xradius = 2.0 * radius;
		yradius = 17.28;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Mimas") {
		name == "Mimas";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.031; //.00003
		colorR = 0.2;
		colorG = 0.7;
		colorB = 0.5;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.002580);
		radius = edist*.031+1;
		orb_ecc = 0.0202;
		xradius = 2.0 * radius;
		yradius = 1.51;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Rhea") {
		name == "Rhea";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.12; //.0017
		colorR = 0.2;
		colorG = 0.7;
		colorB = 0.5;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.01237);
		radius = edist*.12+1;
		orb_ecc = 0.00126;
		xradius = 2.0 * radius;
		yradius = 0.345;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Tethys") {
		name == "Tethys";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.083; //.0006
		colorR = 0.2;
		colorG = 0.7;
		colorB = 0.5;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.005169);
		radius = edist*.083+1;
		orb_ecc = 0.0001;
		xradius = 2.0 * radius;
		yradius = 1.12;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Titan") {
		name == "Titan";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.404; //.0660
		colorR = 0.2;
		colorG = 0.7;
		colorB = 0.5;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.04366);
		radius = edist*.404+1;
		orb_ecc = 0.0288;
		xradius = 2.0 * radius;
		yradius = 0.349;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Ariel") {
		name == "Ariel";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.091; //.0008
		colorR = 0.5;
		colorG = 0.2;
		colorB = 1.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.006899);
		radius = edist*.091+1;
		orb_ecc = 0.0012;
		xradius = 2.0 * radius;
		yradius = 0.260;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Miranda") {
		name == "Miranda";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.037; //.00005
		colorR = 0.5;
		colorG = 0.2;
		colorB = 1.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.0038699);
		radius = edist*.037+1;
		orb_ecc = 0.0013;
		xradius = 2.0 * radius;
		yradius = 4.232;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Oberon") {
		name == "Oberon";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.12; //.0017
		colorR = 0.5;
		colorG = 0.2;
		colorB = 1.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.03686);
		radius = edist*.12+1;
		orb_ecc = 0.0014;
		xradius = 2.0 * radius;
		yradius = .058;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Titania") {
		name == "Titania";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.124; //.0019
		colorR = 0.5;
		colorG = 0.2;
		colorB = 1.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.02384);
		radius = edist*.124+1;
		orb_ecc = 0.0011;
		xradius = 2.0 * radius;
		yradius = 0.340;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Umbriel") {
		name == "Umbriel";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.092; //.0008
		colorR = 0.5;
		colorG = 0.2;
		colorB = 1.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.01135);
		radius = edist*.092+1;
		orb_ecc = 0.0039;
		xradius = 2.0 * radius;
		yradius = 0.128;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Proteus") {
		name == "Proteus";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.033; //.000035
		colorR = 1.0;
		colorG = 0.2;
		colorB = 0.5;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.003348);
		radius = edist*.033+1;
		orb_ecc = 0.00054;
		xradius = 2.0 * radius;
		yradius = 0.524;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Triton") {
		name == "Triton";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.212; //.0096
		colorR = 1.0;
		colorG = 0.2;
		colorB = 0.5;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 *(0-0.01609));
		radius = edist*.212+1;
		orb_ecc = 0.000016;
		xradius = 2.0 * radius;
		yradius = 129.812;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
	if(NameOfMoon == "Charon") {
		name == "Charon";
		transX = 0.0;
		transY = 0.0;
		transZ = 0.0;
		size = esize*.095; //.0008
		colorR = 1.0;
		colorG = 1.0;
		colorB = 1.0;
		rotX = 0.0;
		rotY = 0.0;
		rotZ = 0.0;
		cur_deg = 0.0;
		deg_inc = 360.0 / (365.25 * 0.01749);
		radius = edist*.095+1;
		orb_ecc = 0.0022;
		xradius = 2.0 * radius;
		yradius = 112.783;
		zradius = sqrt(1-(orb_ecc*orb_ecc)) * xradius;
	}
}

void Moon::updateMoon(double value, Planet p) {
	
	transX = p.transX + xradius*sin(cur_deg*PI/180.0) - (orb_ecc*radius);
	transY = p.transY + radius*(p.orb_tilt*PI/180)*sin(cur_deg*PI/180.0);
	transZ = p.transZ + zradius*cos(cur_deg*PI/180.0);

	cur_deg = cur_deg + (deg_inc*value); // add dec_inc * value (value is time scale factor from main)
	
	if(cur_deg >= 360.0)
	{
		cur_deg = cur_deg - 360.0;
	}
}

